<template>
  <div class="app-container">


    <div class="filter-container">

      <el-input v-model="listQuery.title" placeholder="Title" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
<!--      <el-select v-model="listQuery.importance" placeholder="Imp" clearable style="width: 90px" class="filter-item">-->
<!--        <el-option v-for="item in importanceOptions" :key="item" :label="item" :value="item" />-->
<!--      </el-select>-->
<!--      <el-select v-model="listQuery.type" placeholder="Type" clearable class="filter-item" style="width: 130px">-->
<!--        <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name+'('+item.key+')'" :value="item.key" />-->
<!--      </el-select>-->
<!--      <el-select v-model="listQuery.sort" style="width: 140px" class="filter-item" @change="handleFilter">-->
<!--        <el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" />-->
<!--      </el-select>-->
<!--      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">-->
<!--        Search-->
<!--      </el-button>-->
<!--      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">-->
<!--        Add-->
<!--      </el-button>-->
<!--      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">-->
<!--        Export-->
<!--      </el-button>-->
      <el-checkbox  class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">
        reviewer
      </el-checkbox>
    </div>



    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      style="width: 100%;"
      highlight-current-row
    >
      <el-table-column align="center" label="ID" v-if="false">
        <template slot-scope="scope" >
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="编码" align="center">
        <template slot-scope="scope">
          {{ scope.row.code }}
        </template>
      </el-table-column>
      <el-table-column label="名称"  align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否启用"  align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.enable_flag==1">启用</span>
          <span style="color: red" v-if="scope.row.enable_flag==0">禁用</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间"  align="center">
        <template slot-scope="scope">
          {{ scope.row.create_time }}
        </template>
      </el-table-column>
      <el-table-column label="创建人"  align="center">
        <template slot-scope="scope">
          {{ scope.row.create_by }}
        </template>
      </el-table-column>
      <el-table-column label="修改人"  align="center">
        <template slot-scope="scope">
          {{ scope.row.update_by }}
        </template>
      </el-table-column>
      <el-table-column label="修改时间"  align="center">
        <template slot-scope="scope">
          {{ scope.row.update_time }}
        </template>
      </el-table-column>
      <el-table-column label="操作"  width="400px" align="center">
        <template slot-scope="scope">
          <el-button  v-if="scope.row.enable_flag==0"  type="primary" size="mini" @click="updateEnableStatule(scope.row,1)">
            启用
          </el-button>
          <el-button  v-if="scope.row.enable_flag==1"  type="danger" size="mini"  @click="updateEnableStatule(scope.row,0)">
             禁用
          </el-button>

          <el-button type="success" size="mini" @click="update(scope.row)">
            修改
          </el-button>

          <el-button  size="mini" type="danger" @click="handleUpdate(scope.row.id)">
            删除
          </el-button>
          <div>
            <br>
          </div>

          <el-button  size="mini" type="primary" @click="handleUpdate(scope.row.id)">
            查看值集
          </el-button>
          <el-button  size="mini" type="primary" @click="handleUpdate(scope.row.id)">
            编辑值集
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="10"
        align="right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400">
      </el-pagination>
    </div>
    <el-dialog title="修改页面" :visible.sync="dialogFormVisible"  label-width="70px">
      <el-form ref="dataForm" :model="updateVal" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
        <!--      <el-form-item label="Type" prop="type">-->
        <!--        <el-select v-model="temp.type" class="filter-item" placeholder="Please select">-->
        <!--          <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />-->
        <!--        </el-select>-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="Date" prop="timestamp">-->
        <!--        <el-date-picker v-model="temp.timestamp" type="datetime" placeholder="Please pick a date" />-->
        <!--      </el-form-item>-->
        <el-form-item label="编码" prop="title">
          <el-input v-model="updateVal.code" disabled="disabled" />
        </el-form-item>
        <el-form-item label="名称" prop="title">
          <el-input v-model="updateVal.name" />
        </el-form-item>
        <el-form-item>
          <el-radio v-model="updateVal.enable_flag"  label=0>禁用</el-radio>
          <el-radio v-model="updateVal.enable_flag"  label=1>启用</el-radio>
        </el-form-item>
        <!--      <el-form-item label="Imp">-->
        <!--        <el-rate v-model="temp.importance" :colors="['#99A9BF', '#F7BA2A', '#FF9900']" :max="3" style="margin-top:8px;" />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="Remark">-->
        <!--        <el-input v-model="temp.remark" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="Please input" />-->
        <!--      </el-form-item>-->
      </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">
              取消
            </el-button>
<!--        @click="dialogStatus==='create'?createData():updateData()"    \-->
            <el-button type="primary" >
              保存
            </el-button>
          </div>
    </el-dialog>
  </div>


<!--   编辑 or 添加页面-->


</template>

<script>
import { getList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [
        {
          id: 1,
          code: "enable_code",
          name: "禁用启用",
          enable_flag: 0,
          del_flag: 0,
          create_by: "wkt",
          create_time: "2021-03-24 20:36:32",
          update_by: "wkt",
          update_time: "2021-03-24 20:36:49"
        }
      ],
      listLoading: true,
      listQuery:{
        title: 'nisnisnisni'
      },
      dialogFormVisible: false,
      updateVal:{

      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getList().then(response => {
        // this.list = response.data.items
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    handleUpdate(val){
      console.log(`当前id: ${val}`)
    },
    updateEnableStatule(val,status){
      val.enable_flag=status;
    },
    update(val){

      this.updateVal  = JSON.parse(JSON.stringify(val));
      this.dialogFormVisible=true;
    }
  }
}
</script>
